Doc and style improvements
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
1 <?php
2
3 /**
4 * Abstract class to define pages for the web installer.
5 */
6 abstract class WebInstallerPage {
7
8 /**
9 * The WebInstaller object this WebInstallerPage belongs to.
10 *
11 * @var WebInstaller
12 */
13 public $parent;
14
15 public abstract function execute();
16
17 public function __construct( WebInstaller $parent ) {
18 // TODO: This field is not defined??
19 $this->parent = $parent;
20 }
21
22 public function addHTML( $html ) {
23 $this->parent->output->addHTML( $html );
24 }
25
26 public function startForm() {
27 $this->addHTML(
28 "<div class=\"config-section\">\n" .
29 Xml::openElement(
30 'form',
31 array(
32 'method' => 'post',
33 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
34 )
35 ) . "\n"
36 );
37 }
38
39 public function endForm( $continue = 'continue' ) {
40 $this->parent->output->outputWarnings();
41 $s = "<div class=\"config-submit\">\n";
42 $id = $this->getId();
43
44 if ( $id === false ) {
45 $s .= Xml::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
46 }
47
48 if ( $continue ) {
49 // Fake submit button for enter keypress
50 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
51 array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n";
52 }
53
54 if ( $id !== 0 ) {
55 $s .= Xml::submitButton( wfMsg( 'config-back' ),
56 array(
57 'name' => 'submit-back',
58 'tabindex' => $this->parent->nextTabIndex()
59 ) ) . "\n";
60 }
61
62 if ( $continue ) {
63 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
64 array(
65 'name' => "submit-$continue",
66 'tabindex' => $this->parent->nextTabIndex(),
67 ) ) . "\n";
68 }
69
70 $s .= "</div></form></div>\n";
71 $this->addHTML( $s );
72 }
73
74 public function getName() {
75 return str_replace( 'WebInstaller_', '', get_class( $this ) );
76 }
77
78 public function getId() {
79 return array_search( $this->getName(), $this->parent->pageSequence );
80 }
81
82 public function getVar( $var ) {
83 return $this->parent->getVar( $var );
84 }
85
86 public function setVar( $name, $value ) {
87 $this->parent->setVar( $name, $value );
88 }
89
90 }
91
92 class WebInstaller_Language extends WebInstallerPage {
93
94 public function execute() {
95 global $wgLang;
96 $r = $this->parent->request;
97 $userLang = $r->getVal( 'UserLang' );
98 $contLang = $r->getVal( 'ContLang' );
99
100 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
101 if ( !$lifetime ) {
102 $lifetime = 1440; // PHP default
103 }
104
105 if ( $r->wasPosted() ) {
106 # Do session test
107 if ( $this->parent->getSession( 'test' ) === null ) {
108 $requestTime = $r->getVal( 'LanguageRequestTime' );
109 if ( !$requestTime ) {
110 // The most likely explanation is that the user was knocked back
111 // from another page on POST due to session expiry
112 $msg = 'config-session-expired';
113 } elseif ( time() - $requestTime > $lifetime ) {
114 $msg = 'config-session-expired';
115 } else {
116 $msg = 'config-no-session';
117 }
118 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
119 } else {
120 $languages = Language::getLanguageNames();
121 if ( isset( $languages[$userLang] ) ) {
122 $this->setVar( '_UserLang', $userLang );
123 }
124 if ( isset( $languages[$contLang] ) ) {
125 $this->setVar( 'wgLanguageCode', $contLang );
126 }
127 return 'continue';
128 }
129 } elseif ( $this->parent->showSessionWarning ) {
130 # The user was knocked back from another page to the start
131 # This probably indicates a session expiry
132 $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
133 }
134
135 $this->parent->setSession( 'test', true );
136
137 if ( !isset( $languages[$userLang] ) ) {
138 $userLang = $this->getVar( '_UserLang', 'en' );
139 }
140 if ( !isset( $languages[$contLang] ) ) {
141 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
142 }
143 $this->startForm();
144 $s =
145 Xml::hidden( 'LanguageRequestTime', time() ) .
146 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang ) .
147 $this->parent->getHelpBox( 'config-your-language-help' ) .
148 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang ) .
149 $this->parent->getHelpBox( 'config-wiki-language-help' );
150
151
152 $this->addHTML( $s );
153 $this->endForm();
154 }
155
156 /**
157 * Get a <select> for selecting languages.
158 */
159 public function getLanguageSelector( $name, $label, $selectedCode ) {
160 global $wgDummyLanguageCodes;
161 $s = Xml::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
162
163 $languages = Language::getLanguageNames();
164 ksort( $languages );
165 $dummies = array_flip( $wgDummyLanguageCodes );
166 foreach ( $languages as $code => $lang ) {
167 if ( isset( $dummies[$code] ) ) continue;
168 $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
169 }
170 $s .= "\n</select>\n";
171 return $this->parent->label( $label, $name, $s );
172 }
173
174 }
175
176 class WebInstaller_Welcome extends WebInstallerPage {
177
178 public function execute() {
179 if ( $this->parent->request->wasPosted() ) {
180 if ( $this->getVar( '_Environment' ) ) {
181 return 'continue';
182 }
183 }
184 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
185 $status = $this->parent->doEnvironmentChecks();
186 if ( $status ) {
187 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright', wfMsg( 'config-authors' ) ) );
188 $this->startForm();
189 $this->endForm();
190 }
191 }
192
193 }
194
195 class WebInstaller_DBConnect extends WebInstallerPage {
196
197 public function execute() {
198 $r = $this->parent->request;
199 if ( $r->wasPosted() ) {
200 $status = $this->submit();
201 if ( $status->isGood() ) {
202 $this->setVar( '_UpgradeDone', false );
203 return 'continue';
204 } else {
205 $this->parent->showStatusBox( $status );
206 }
207 }
208
209 $this->startForm();
210
211 $types = "<ul class=\"config-settings-block\">\n";
212 $settings = '';
213 $defaultType = $this->getVar( 'wgDBtype' );
214 foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
215 $installer = $this->parent->getDBInstaller( $type );
216 $types .=
217 '<li>' .
218 Xml::radioLabel(
219 $installer->getReadableName(),
220 'DBType',
221 $type,
222 "DBType_$type",
223 $type == $defaultType,
224 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
225 ) .
226 "</li>\n";
227
228 $settings .=
229 Xml::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
230 Xml::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
231 $installer->getConnectForm() .
232 "</div>\n";
233 }
234 $types .= "</ul><br clear=\"left\"/>\n";
235
236 $this->addHTML(
237 $this->parent->label( 'config-db-type', false, $types ) .
238 $settings
239 );
240
241 $this->endForm();
242 }
243
244 public function submit() {
245 $r = $this->parent->request;
246 $type = $r->getVal( 'DBType' );
247 $this->setVar( 'wgDBtype', $type );
248 $installer = $this->parent->getDBInstaller( $type );
249 if ( !$installer ) {
250 return Status::newFatal( 'config-invalid-db-type' );
251 }
252 return $installer->submitConnectForm();
253 }
254
255 }
256
257 class WebInstaller_Upgrade extends WebInstallerPage {
258
259 public function execute() {
260 if ( $this->getVar( '_UpgradeDone' ) ) {
261 if ( $this->parent->request->wasPosted() ) {
262 // Done message acknowledged
263 return 'continue';
264 } else {
265 // Back button click
266 // Show the done message again
267 // Make them click back again if they want to do the upgrade again
268 $this->showDoneMessage();
269 return 'output';
270 }
271 }
272
273 // wgDBtype is generally valid here because otherwise the previous page
274 // (connect) wouldn't have declared its happiness
275 $type = $this->getVar( 'wgDBtype' );
276 $installer = $this->parent->getDBInstaller( $type );
277
278 if ( !$installer->needsUpgrade() ) {
279 return 'skip';
280 }
281
282 if ( $this->parent->request->wasPosted() ) {
283 $this->addHTML(
284 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
285 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
286 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
287 );
288 $this->parent->output->flush();
289 $result = $installer->doUpgrade();
290 $this->addHTML( '</textarea>
291 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
292 $this->parent->output->flush();
293 if ( $result ) {
294 $this->setVar( '_UpgradeDone', true );
295 $this->showDoneMessage();
296 return 'output';
297 }
298 }
299
300 $this->startForm();
301 $this->addHTML( $this->parent->getInfoBox(
302 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
303 $this->endForm();
304 }
305
306 public function showDoneMessage() {
307 $this->startForm();
308 $this->addHTML(
309 $this->parent->getInfoBox(
310 wfMsgNoTrans( 'config-upgrade-done',
311 $GLOBALS['wgServer'] .
312 $this->getVar( 'wgScriptPath' ) . '/index' .
313 $this->getVar( 'wgScriptExtension' )
314 ), 'tick-32.png'
315 )
316 );
317 $this->endForm( 'regenerate' );
318 }
319
320 }
321
322 class WebInstaller_DBSettings extends WebInstallerPage {
323
324 public function execute() {
325 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
326
327 $r = $this->parent->request;
328 if ( $r->wasPosted() ) {
329 $status = $installer->submitSettingsForm();
330 if ( $status === false ) {
331 return 'skip';
332 } elseif ( $status->isGood() ) {
333 return 'continue';
334 } else {
335 $this->parent->showStatusBox( $status );
336 }
337 }
338
339 $form = $installer->getSettingsForm();
340 if ( $form === false ) {
341 return 'skip';
342 }
343
344 $this->startForm();
345 $this->addHTML( $form );
346 $this->endForm();
347 }
348
349 }
350
351 class WebInstaller_Name extends WebInstallerPage {
352
353 public function execute() {
354 $r = $this->parent->request;
355 if ( $r->wasPosted() ) {
356 if ( $this->submit() ) {
357 return 'continue';
358 }
359 }
360
361 $this->startForm();
362
363 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
364 $this->setVar( 'wgSitename', '' );
365 }
366
367 // Set wgMetaNamespace to something valid before we show the form.
368 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
369 $metaNS = $this->getVar( 'wgMetaNamespace' );
370 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
371
372 $this->addHTML(
373 $this->parent->getTextBox( array(
374 'var' => 'wgSitename',
375 'label' => 'config-site-name',
376 ) ) .
377 $this->parent->getHelpBox( 'config-site-name-help' ) .
378 $this->parent->getRadioSet( array(
379 'var' => '_NamespaceType',
380 'label' => 'config-project-namespace',
381 'itemLabelPrefix' => 'config-ns-',
382 'values' => array( 'site-name', 'generic', 'other' ),
383 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
384 ) ) .
385 $this->parent->getTextBox( array(
386 'var' => 'wgMetaNamespace',
387 'label' => '',
388 'attribs' => array( 'disabled' => '' ),
389 ) ) .
390 $this->parent->getHelpBox( 'config-project-namespace-help' ) .
391 $this->parent->getFieldsetStart( 'config-admin-box' ) .
392 $this->parent->getTextBox( array(
393 'var' => '_AdminName',
394 'label' => 'config-admin-name'
395 ) ) .
396 $this->parent->getPasswordBox( array(
397 'var' => '_AdminPassword',
398 'label' => 'config-admin-password',
399 ) ) .
400 $this->parent->getPasswordBox( array(
401 'var' => '_AdminPassword2',
402 'label' => 'config-admin-password-confirm'
403 ) ) .
404 $this->parent->getHelpBox( 'config-admin-help' ) .
405 $this->parent->getTextBox( array(
406 'var' => '_AdminEmail',
407 'label' => 'config-admin-email'
408 ) ) .
409 $this->parent->getHelpBox( 'config-admin-email-help' ) .
410 $this->parent->getCheckBox( array(
411 'var' => '_Subscribe',
412 'label' => 'config-subscribe'
413 ) ) .
414 $this->parent->getHelpBox( 'config-subscribe-help' ) .
415 $this->parent->getFieldsetEnd() .
416 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
417 $this->parent->getRadioSet( array(
418 'var' => '_SkipOptional',
419 'itemLabelPrefix' => 'config-optional-',
420 'values' => array( 'continue', 'skip' )
421 ) )
422 );
423
424 // Restore the default value
425 $this->setVar( 'wgMetaNamespace', $metaNS );
426
427 $this->endForm();
428 return 'output';
429 }
430
431 public function submit() {
432 $retVal = true;
433 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
434 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
435 '_Subscribe', '_SkipOptional' ) );
436
437 // Validate site name
438 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
439 $this->parent->showError( 'config-site-name-blank' );
440 $retVal = false;
441 }
442
443 // Fetch namespace
444 $nsType = $this->getVar( '_NamespaceType' );
445 if ( $nsType == 'site-name' ) {
446 $name = $this->getVar( 'wgSitename' );
447 // Sanitize for namespace
448 // This algorithm should match the JS one in WebInstallerOutput.php
449 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
450 $name = str_replace( '&', '&amp;', $name );
451 $name = preg_replace( '/__+/', '_', $name );
452 $name = ucfirst( trim( $name, '_' ) );
453 } elseif ( $nsType == 'generic' ) {
454 $name = wfMsg( 'config-ns-generic' );
455 } else { // other
456 $name = $this->getVar( 'wgMetaNamespace' );
457 }
458
459 // Validate namespace
460 if ( strpos( $name, ':' ) !== false ) {
461 $good = false;
462 } else {
463 // Title-style validation
464 $title = Title::newFromText( $name );
465 if ( !$title ) {
466 $good = $nsType == 'site-name' ? true : false;
467 } else {
468 $name = $title->getDBkey();
469 $good = true;
470 }
471 }
472 if ( !$good ) {
473 $this->parent->showError( 'config-ns-invalid', $name );
474 $retVal = false;
475 }
476 $this->setVar( 'wgMetaNamespace', $name );
477
478 // Validate username for creation
479 $name = $this->getVar( '_AdminName' );
480 if ( strval( $name ) === '' ) {
481 $this->parent->showError( 'config-admin-name-blank' );
482 $cname = $name;
483 $retVal = false;
484 } else {
485 $cname = User::getCanonicalName( $name, 'creatable' );
486 if ( $cname === false ) {
487 $this->parent->showError( 'config-admin-name-invalid', $name );
488 $retVal = false;
489 } else {
490 $this->setVar( '_AdminName', $cname );
491 }
492 }
493
494 // Validate password
495 $msg = false;
496 $pwd = $this->getVar( '_AdminPassword' );
497 $user = User::newFromName( $cname );
498 $valid = $user->getPasswordValidity( $pwd );
499 if ( strval( $pwd ) === '' ) {
500 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
501 # This message is more specific and helpful.
502 $msg = 'config-admin-password-blank';
503 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
504 $msg = 'config-admin-password-mismatch';
505 } elseif ( $valid !== true ) {
506 # As of writing this will only catch the username being e.g. 'FOO' and
507 # the password 'foo'
508 $msg = $valid;
509 }
510 if ( $msg !== false ) {
511 $this->parent->showError( $msg );
512 $this->setVar( '_AdminPassword', '' );
513 $this->setVar( '_AdminPassword2', '' );
514 $retVal = false;
515 }
516 return $retVal;
517 }
518
519 }
520
521 class WebInstaller_Options extends WebInstallerPage {
522
523 public function execute() {
524 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
525 return 'skip';
526 }
527 if ( $this->parent->request->wasPosted() ) {
528 if ( $this->submit() ) {
529 return 'continue';
530 }
531 }
532
533 $this->startForm();
534 $this->addHTML(
535 # User Rights
536 $this->parent->getRadioSet( array(
537 'var' => '_RightsProfile',
538 'label' => 'config-profile',
539 'itemLabelPrefix' => 'config-profile-',
540 'values' => array_keys( $this->parent->rightsProfiles ),
541 ) ) .
542 $this->parent->getHelpBox( 'config-profile-help' ) .
543
544 # Licensing
545 $this->parent->getRadioSet( array(
546 'var' => '_LicenseCode',
547 'label' => 'config-license',
548 'itemLabelPrefix' => 'config-license-',
549 'values' => array_keys( $this->parent->licenses ),
550 'commonAttribs' => array( 'class' => 'licenseRadio' ),
551 ) ) .
552 $this->getCCChooser() .
553 $this->parent->getHelpBox( 'config-license-help' ) .
554
555 # E-mail
556 $this->parent->getFieldsetStart( 'config-email-settings' ) .
557 $this->parent->getCheckBox( array(
558 'var' => 'wgEnableEmail',
559 'label' => 'config-enable-email',
560 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
561 ) ) .
562 $this->parent->getHelpBox( 'config-enable-email-help' ) .
563 "<div id=\"emailwrapper\">" .
564 $this->parent->getTextBox( array(
565 'var' => 'wgPasswordSender',
566 'label' => 'config-email-sender'
567 ) ) .
568 $this->parent->getHelpBox( 'config-email-sender-help' ) .
569 $this->parent->getCheckBox( array(
570 'var' => 'wgEnableUserEmail',
571 'label' => 'config-email-user',
572 ) ) .
573 $this->parent->getHelpBox( 'config-email-user-help' ) .
574 $this->parent->getCheckBox( array(
575 'var' => 'wgEnotifUserTalk',
576 'label' => 'config-email-usertalk',
577 ) ) .
578 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
579 $this->parent->getCheckBox( array(
580 'var' => 'wgEnotifWatchlist',
581 'label' => 'config-email-watchlist',
582 ) ) .
583 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
584 $this->parent->getCheckBox( array(
585 'var' => 'wgEmailAuthentication',
586 'label' => 'config-email-auth',
587 ) ) .
588 $this->parent->getHelpBox( 'config-email-auth-help' ) .
589 "</div>" .
590 $this->parent->getFieldsetEnd()
591 );
592
593 $extensions = $this->parent->findExtensions();
594 if( $extensions ) {
595 $extHtml = $this->parent->getFieldsetStart( 'config-extensions' );
596 foreach( array_keys($extensions) as $ext ) {
597 $extHtml .= $this->parent->getCheckBox( array(
598 'var' => "ext-$ext",
599 'rawtext' => $ext,
600 ) );
601 }
602 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
603 $this->parent->getFieldsetEnd();
604 $this->addHTML( $extHtml );
605 }
606
607 $this->addHTML(
608 # Uploading
609 $this->parent->getFieldsetStart( 'config-upload-settings' ) .
610 $this->parent->getCheckBox( array(
611 'var' => 'wgEnableUploads',
612 'label' => 'config-upload-enable',
613 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
614 ) ) .
615 $this->parent->getHelpBox( 'config-upload-help' ) .
616 '<div id="uploadwrapper" style="display: none;">' .
617 $this->parent->getTextBox( array(
618 'var' => 'wgDeletedDirectory',
619 'label' => 'config-upload-deleted',
620 ) ) .
621 $this->parent->getHelpBox( 'config-upload-deleted-help' ) .
622 '</div>' .
623 $this->parent->getTextBox( array(
624 'var' => 'wgLogo',
625 'label' => 'config-logo'
626 ) ) .
627 $this->parent->getHelpBox( 'config-logo-help' )
628 );
629 $canUse = $this->getVar( '_ExternalHTTP' ) ?
630 'config-instantcommons-good' : 'config-instantcommons-bad';
631 $this->addHTML(
632 $this->parent->getCheckBox( array(
633 'var' => 'wgUseInstantCommons',
634 'label' => 'config-instantcommons',
635 ) ) .
636 $this->parent->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) .
637 $this->parent->getFieldsetEnd()
638 );
639
640 $caches = array( 'none' );
641 if( count( $this->getVar( '_Caches' ) ) ) {
642 $caches[] = 'accel';
643 }
644 $caches[] = 'memcached';
645
646 $this->addHTML(
647 # Advanced settings
648 $this->parent->getFieldsetStart( 'config-advanced-settings' ) .
649 # Object cache settings
650 $this->parent->getRadioSet( array(
651 'var' => 'wgMainCacheType',
652 'label' => 'config-cache-options',
653 'itemLabelPrefix' => 'config-cache-',
654 'values' => $caches,
655 'value' => 'none',
656 ) ) .
657 $this->parent->getHelpBox( 'config-cache-help' ) .
658 '<div id="config-memcachewrapper">' .
659 $this->parent->getTextBox( array(
660 'var' => '_MemCachedServers',
661 'label' => 'config-memcached-servers',
662 ) ) .
663 $this->parent->getHelpBox( 'config-memcached-help' ) . '</div>' .
664 $this->parent->getFieldsetEnd()
665 );
666 $this->endForm();
667 }
668
669 public function getCCPartnerUrl() {
670 global $wgServer;
671 $exitUrl = $wgServer . $this->parent->getUrl( array(
672 'page' => 'Options',
673 'SubmitCC' => 'indeed',
674 'config__LicenseCode' => 'cc',
675 'config_wgRightsUrl' => '[license_url]',
676 'config_wgRightsText' => '[license_name]',
677 'config_wgRightsIcon' => '[license_button]',
678 ) );
679 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
680 '/skins/common/config-cc.css';
681 $iframeUrl = 'http://creativecommons.org/license/?' .
682 wfArrayToCGI( array(
683 'partner' => 'MediaWiki',
684 'exit_url' => $exitUrl,
685 'lang' => $this->getVar( '_UserLang' ),
686 'stylesheet' => $styleUrl,
687 ) );
688 return $iframeUrl;
689 }
690
691 public function getCCChooser() {
692 $iframeAttribs = array(
693 'class' => 'config-cc-iframe',
694 'name' => 'config-cc-iframe',
695 'id' => 'config-cc-iframe',
696 'frameborder' => 0,
697 'width' => '100%',
698 'height' => '100%',
699 );
700 if ( $this->getVar( '_CCDone' ) ) {
701 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
702 } else {
703 $iframeAttribs['src'] = $this->getCCPartnerUrl();
704 }
705
706 return
707 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
708 Xml::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
709 "</div>\n";
710 }
711
712 public function getCCDoneBox() {
713 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
714 // If you change this height, also change it in config.css
715 $expandJs = str_replace( '$1', '54em', $js );
716 $reduceJs = str_replace( '$1', '70px', $js );
717 return
718 '<p>'.
719 Xml::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
720 '&#160;&#160;' .
721 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
722 "</p>\n" .
723 "<p style=\"text-align: center\">" .
724 Xml::element( 'a',
725 array(
726 'href' => $this->getCCPartnerUrl(),
727 'onclick' => $expandJs,
728 ),
729 wfMsg( 'config-cc-again' )
730 ) .
731 "</p>\n" .
732 "<script type=\"text/javascript\">\n" .
733 # Reduce the wrapper div height
734 htmlspecialchars( $reduceJs ) .
735 "\n" .
736 "</script>\n";
737 }
738
739 public function submitCC() {
740 $newValues = $this->parent->setVarsFromRequest(
741 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
742 if ( count( $newValues ) != 3 ) {
743 $this->parent->showError( 'config-cc-error' );
744 return;
745 }
746 $this->setVar( '_CCDone', true );
747 $this->addHTML( $this->getCCDoneBox() );
748 }
749
750 public function submit() {
751 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
752 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUpload', 'wgLogo',
753 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
754 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
755 'wgUseInstantCommons' ) );
756
757 if ( !in_array( $this->getVar( '_RightsProfile' ),
758 array_keys( $this->parent->rightsProfiles ) ) )
759 {
760 reset( $this->parent->rightsProfiles );
761 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
762 }
763
764 $code = $this->getVar( '_LicenseCode' );
765 if ( $code == 'cc-choose' ) {
766 if ( !$this->getVar( '_CCDone' ) ) {
767 $this->parent->showError( 'config-cc-not-chosen' );
768 return false;
769 }
770 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
771 $entry = $this->parent->licenses[$code];
772 if ( isset( $entry['text'] ) ) {
773 $this->setVar( 'wgRightsText', $entry['text'] );
774 } else {
775 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
776 }
777 $this->setVar( 'wgRightsUrl', $entry['url'] );
778 $this->setVar( 'wgRightsIcon', $entry['icon'] );
779 } else {
780 $this->setVar( 'wgRightsText', '' );
781 $this->setVar( 'wgRightsUrl', '' );
782 $this->setVar( 'wgRightsIcon', '' );
783 }
784
785 $exts = $this->parent->getVar( '_Extensions' );
786 foreach( $exts as $key => $ext ) {
787 if( !$this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
788 unset( $exts[$key] );
789 }
790 }
791 $this->parent->setVar( '_Extensions', $exts );
792 return true;
793 }
794
795 }
796
797 class WebInstaller_Install extends WebInstallerPage {
798
799 public function execute() {
800 if( $this->parent->request->wasPosted() ) {
801 return 'continue';
802 } elseif( $this->getVar( '_InstallDone' ) ) {
803 $this->startForm();
804 $status = new Status();
805 $status->warning( 'config-install-alreadydone' );
806 $this->parent->showStatusBox( $status );
807 } else {
808 $this->startForm();
809 $this->addHTML("<ul>");
810 $this->parent->performInstallation(
811 array( $this, 'startStage'),
812 array( $this, 'endStage' )
813 );
814 $this->addHTML("</ul>");
815 }
816 $this->endForm();
817 return true;
818 }
819
820 public function startStage( $step ) {
821 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
822 }
823
824 public function endStage( $step, $status ) {
825 $success = $status->isGood();
826 $msg = $success ? 'config-install-step-done' : 'config-install-step-failed';
827 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
828 if ( !$success ) {
829 $html = "<span class=\"error\">$html</span>";
830 }
831 $this->addHTML( $html . "</li>\n" );
832 if( !$success ) {
833 $this->parent->showStatusBox( $status );
834 }
835 }
836
837 }
838
839 class WebInstaller_Complete extends WebInstallerPage {
840
841 public function execute() {
842 global $IP;
843 $this->startForm();
844 $this->addHTML(
845 $this->parent->getInfoBox(
846 wfMsgNoTrans( 'config-install-done',
847 $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) ),
848 $GLOBALS['wgServer'] .
849 $this->getVar( 'wgScriptPath' ) . '/index' .
850 $this->getVar( 'wgScriptExtension' )
851 ), 'tick-32.png'
852 )
853 );
854 $this->endForm( false );
855 }
856 }
857
858 class WebInstaller_Restart extends WebInstallerPage {
859
860 public function execute() {
861 $r = $this->parent->request;
862 if ( $r->wasPosted() ) {
863 $really = $r->getVal( 'submit-restart' );
864 if ( $really ) {
865 $this->parent->session = array();
866 $this->parent->happyPages = array();
867 $this->parent->settings = array();
868 }
869 return 'continue';
870 }
871
872 $this->startForm();
873 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
874 $this->addHTML( $s );
875 $this->endForm( 'restart' );
876 }
877
878 }
879
880 abstract class WebInstaller_Document extends WebInstallerPage {
881
882 protected abstract function getFileName();
883
884 public function execute() {
885 $text = $this->getFileContents();
886 $this->parent->output->addWikiText( $text );
887 $this->startForm();
888 $this->endForm( false );
889 }
890
891 public function getFileContents() {
892 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
893 }
894
895 protected function formatTextFile( $text ) {
896 $text = str_replace( array( '<', '{{', '[[' ),
897 array( '&lt;', '&#123;&#123;', '&#91;&#91;' ), $text );
898 // replace numbering with [1], [2], etc with MW-style numbering
899 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
900 // join word-wrapped lines into one
901 do {
902 $prev = $text;
903 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
904 } while ( $text != $prev );
905 // turn (bug nnnn) into links
906 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
907 // add links to manual to every global variable mentioned
908 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
909 // special case for <pre> - formatted links
910 do {
911 $prev = $text;
912 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
913 } while ( $text != $prev );
914 return $text;
915 }
916
917 private function replaceBugLinks( $matches ) {
918 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
919 $matches[1] . ' bug ' . $matches[1] . ']</span>';
920 }
921
922 private function replaceConfigLinks( $matches ) {
923 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
924 $matches[1] . ' ' . $matches[1] . ']</span>';
925 }
926
927 }
928
929 class WebInstaller_Readme extends WebInstaller_Document {
930
931 protected function getFileName() { return 'README'; }
932
933 public function getFileContents() {
934 return $this->formatTextFile( parent::getFileContents() );
935 }
936
937 }
938
939 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
940
941 protected function getFileName() { return 'RELEASE-NOTES'; }
942
943 public function getFileContents() {
944 return $this->formatTextFile( parent::getFileContents() );
945 }
946
947 }
948
949 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
950
951 protected function getFileName() { return 'UPGRADE'; }
952
953 public function getFileContents() {
954 return $this->formatTextFile( parent::getFileContents() );
955 }
956
957 }
958
959 class WebInstaller_Copying extends WebInstaller_Document {
960
961 protected function getFileName() { return 'COPYING'; }
962
963 public function getFileContents() {
964 $text = parent::getFileContents();
965 $text = str_replace( "\x0C", '', $text );
966 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
967 $text = '<tt>' . nl2br( $text ) . '</tt>';
968 return $text;
969 }
970
971 private static function replaceLeadingSpaces( $matches ) {
972 return "\n" . str_repeat( '&#160;', strlen( $matches[0] ) );
973 }
974
975 }